import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
axios.defaults.baseURL = "http://localhost:8888/api/private/v1";
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem("token");
  return config;
}, (error) => {
  return Promise.reject(error);
});

// 树形数据
import treeGrid from 'vue-table-with-tree-grid'
Vue.component("tree-table", treeGrid);

import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor);

Vue.prototype.$http = axios;

// CSS
import "/public/css/minireset.css";
import "/public/css/common.css"
import "@/assets/fonts/iconfont.css"
Vue.use(ElementUI)

// 全局过滤器
Vue.filter("timestamp2Date", function (val) {
  return goodsAddTime(val);
});
// 时间格式化     时间戳 --> 日期时间
function goodsAddTime(timestamp) {
  let time = new Date(timestamp * 1000);
  let year = (time.getFullYear() + "").padStart(2, '0');
  let month = (time.getMonth() + 1 + "").padStart(2, '0');
  month = month < 10 ? "0" + month : month;

  let day = (time.getDate() + "").padStart(2, '0');
  let hours = (time.getHours() + "").padStart(2, '0');
  let minutes = (time.getMinutes() + "").padStart(2, '0');
  let seconds = (time.getSeconds() + "").padStart(2, '0');

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')